package de.koller.worlders.engine.entity.zone;

import de.koller.worlders.engine.entity.EntityContainer;
import de.koller.worlders.engine.entity.mo.MovingObject;
import de.koller.worlders.engine.tiles.ITile;
import de.koller.worlders.engine.tiles.data.ITileCreator;
import de.koller.worlders.render.VisualMap;
import de.koller.worlders.render.visual.DisplayRenderObject;

public class ResetZone extends ZoneEffect {
	public static final int GEN_ID = 8;
	
	public static final ITileCreator GEN_INSTANCE = new ITileCreator() {
		@Override public ITile newInstance() {
			return new Zone().addEffect( new ResetZone() );
		}

		@Override public DisplayRenderObject getIcon() { return VisualMap.resetOff; }
		@Override public String getName() { return "Reseter"; }
	};
	
	private EntityContainer ec;
	private boolean active = false;
	
	protected ResetZone() {}
	
	@Override
	public void init( Zone z ) {
		super.init( z );
		
		zone = z;
		z.getTile().setVisual( VisualMap.resetOff );
		if( z.root != null ) {
			ec = z.root.getEntityContainer();
			ec.getReseters().add( this );
		}
	}

	@Override
	public void release() {
		super.release();
		
		if( ec != null )
			ec.getReseters().remove( this );
	}

	@Override
	public void enter( MovingObject mo ) {
		if( mo.mostate.isGameplayAffected() )
			ec.reseterEntered( this );
	}

	public Zone getZone() {
		return zone;
	}
	
}
